<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 原始代码
    class Animal {
        constructor(type) {
            this.type = type;
        }

        makeSound() {
            if (this.type === 'dog') {
                return 'Woof!';
            } else if (this.type === 'cat') {
                return 'Meow!';
            } else if (this.type === 'duck') {
                return 'Quack!';
            }
        }
    }

    // 优化后
    class Animal {
        makeSound() {
            throw new Error('This method must be implemented');
        }
    }

    class Dog extends Animal {
        makeSound() {
            return 'Woof!';
        }
    }

    class Cat extends Animal {
        makeSound() {
            return 'Meow!';
        }
    }

    class Duck extends Animal {
        makeSound() {
            return 'Quack!';
        }
    }
</script>
</html>